import {
  Column,
  Entity,
  JoinTable,
  ManyToMany,
  PrimaryGeneratedColumn,
  Tree,
  TreeChildren,
  TreeParent,
} from 'typeorm';
import { Roles } from '../../roles/entities/role.entity';
@Entity()
@Tree('materialized-path')
export class Menu {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  label: string;

  @Column()
  icon: string;

  @Column({ type: 'enum', default: '1', enum: ['1', '0'] })
  active: string;

  @Column({ nullable: true })
  route: string;

  @Column({ nullable: true })
  file: string;

  @Column({ type: 'enum', enum: ['dir', 'menu', 'btn'] })
  type: string;

  @Column({ default: null })
  authority: string;

  @Column()
  sort: number;

  @ManyToMany(() => Roles, (roles) => roles.menus, { cascade: true })
  @JoinTable({ name: 'menu_roles' })
  roles: Roles[];

  @TreeChildren()
  children: Menu[];

  @TreeParent({ onDelete: 'CASCADE' })
  parent: Menu;
}
